<?php

namespace app\common\logic;

class EncryptLogic
{
    const ENCRYPT_KEY = '6';

    /**
     * @Description md5加密
     * @author: zj
     * @param string $str
     * @param string $salt
     * @time 2023/12/02 16:36:56
     * @return string
     */
    public function encryptMD5(string $str, string $salt,string $key = '')
    {
        $encrypt_key = $key ?: self::ENCRYPT_KEY;

        return md5($salt. $str. $encrypt_key. $salt);
    }

    /**
     * @Description 检查md5加密后的字符是否匹配
     * @author: zj
     * @param string $str
     * @param string $salt
     * @param string $md5_str
     * @param string $key
     * @time 2024/07/09 15:57:29
     * @return bool
     */
    public function checkMD5Str(string $str,string $salt,string $md5_str,string $key = '')
    {
        $md5Str = $this->encryptMD5($str,$salt,$key);
        if ($md5_str !== $md5Str) {
            return false;
        }

        return true;
    }

}